﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.UI.WebControls;
using XYTXL.AppCode;
using XYTXL.Data;
using XYTXL.API;


namespace XYTXL.View
{
    public partial class CopyBtn :BasePage
    {
        public int intBtncode
        {
            get
            {
                return int.Parse(Request.QueryString["btncode"].ToString());
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                RepRepeaterData.DataSource = new JH_Auth_MenuB().GetEntities(m => m.isMenu == "Y" && m.FileName != "");
                RepRepeaterData.DataBind();
            }
        }

        protected void btAddBranch_Click(object sender, EventArgs e)
        {
            JH_Auth_Menu Btn = new JH_Auth_MenuB().GetEntities(d => d.AuthCode == intBtncode).SingleOrDefault();
            int A = 0;
            for (int i = 0; i < this.RepRepeaterData.Items.Count; i++)
            {
                CheckBox chkSingle = (CheckBox)this.RepRepeaterData.Items[i].FindControl("ckitem");
                if (chkSingle.Checked)
                {
                    A = A + 1;
                    Label lbAuthCode = (Label)this.RepRepeaterData.Items[i].FindControl("lbAuthCode");
                    string strMenuCode = lbAuthCode.Text;
                    JH_Auth_Menu NewAuth = new JH_Auth_Menu();
                    NewAuth.PAuthCode = int.Parse(strMenuCode);
                    NewAuth.AuthLevel = int.Parse(Btn.AuthLevel.ToString()) - 1;
                    NewAuth.AuthName = Btn.AuthName;
                    NewAuth.FileName = Btn.FileName;
                    NewAuth.IsUse = "Y";
                    NewAuth.Ico = "";
                    NewAuth.isMenu = "N";
                    new JH_Auth_MenuB().Insert(NewAuth);
                }
            }
            if (A == 0)
            {
                AlertMSG("2", "请选择一项记录");
            }
            AlertMSG("2", "复制完成");
        }
    }
}